package com.baidu.day02;

import java.util.ArrayList;
import java.util.List;

/**
 * Create with Intellij IDEA
 *
 * @Author Q
 * @date 2021/11/23/9:57
 */
public class ArrayListRemove {
    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();

        //创建学生对象
        Student s1 = new Student(1,"霍针");
        Student s2 = new Student(2,"吴签");
        Student s3 = new Student(3,"李泽鑫");
        Student s4 = new Student(4,"李泽鑫");

        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);

//        list.remove(s1);
        delByTarget(list,"李泽鑫");

        list.forEach(e-> System.out.println(e));
    }

    private static void delByTarget(List<Student> list, String name) {
        for(int i = 0;i<list.size();i++){
            if(list.get(i).getName().equals(name)){
                list.remove(i);
                i--;
            }
        }

    }
}
